#ifndef ALGEBRA_H_INCLUDED
#define ALGEBRA_H_INCLUDED

#include <UnitTest++/UnitTest++.h>
#include "Common/Common.h"

using namespace cmn;

SUITE( Algebra )
{
	TEST( MatrixInvertions )
	{
		Matr4 identity;

		Transform tr1( Vec2( 2.0f, -1.0f ), 0.25f * Pi, 0.5f );
		Matr4 trMatr = tr1.GetMatrix();
		Matr4 trMatrInv0 = tr1.GetInvMatrix();
		Matr4 trMatrInv1 = trMatr.GetInverted();

		CHECK_ARRAY_CLOSE(trMatrInv0, trMatrInv1, 16, 1e-6f );
	}

	TEST( TransformUsage )
	{
		Vec2 vec = Vec2::Right();
		Transform transform( Vec2( 2.0f, -1.0f ), 0.5f * Pi, 0.5f );

		Vec2 result = transform * vec;
		Vec2 expectedResult = Vec2( 2.0f, -0.5f );

		float dist = Distance( result, expectedResult );
		CHECK_CLOSE(0.0f, dist, 1e-6f );
	}

	TEST( MatrixUsage1 )
	{
		Vec2 vec = Vec2::Right();
		Vec4 vec4 = Vec4( vec, 0.0f, 1.0f );
		Transform transform( Vec2( 2.0f, -1.0f ), 0.5f * Pi, 0.5f );
		Matr4 matr = transform.GetMatrix();

		Vec4 result = vec4 * matr;
		Vec2 result2 = Vec2(result.X, result.Y);
		Vec2 expectedResult = Vec2( 2.0f, -0.5f );

		float dist = Distance( result2, expectedResult );
		CHECK_CLOSE(0.0f, dist, 1e-6f );
	}

	TEST( MatrixUsage2 )
	{
		Vec4 vec = Vec4( Vec2::Zero(), 0.0f, 1.0f );
		Vec4 vecU = Vec4( Vec2::Up(), 0.0f, 1.0f );
		Vec4 vecD = Vec4( Vec2::Down(), 0.0f, 1.0f );
		Vec4 vecL = Vec4( Vec2::Left(), 0.0f, 1.0f );
		Vec4 vecR = Vec4( Vec2::Right(), 0.0f, 1.0f );

		Transform transform( Vec2( 2.0f, -1.0f ), 0.5f * Pi, 0.5f );
		Matr4 matr = transform.GetMatrix();

		Vec4 result = matr * vec;
		Vec4 resultU = matr * vecU;
		Vec4 resultD = matr * vecD;
		Vec4 resultL = matr * vecL;
		Vec4 resultR = matr * vecR;

		Vec2 result2 = Vec2(result.X * result.W, result.Y * result.W);
		Vec2 expectedResult = Vec2( 0.0f, -1.5f );

		float dist = Distance( result2, expectedResult );
		CHECK_CLOSE(0.0f, dist, 1e-6f );
	}

//	TEST_FIXTURE( GameFixture, AllOnes )
//	{
//		rollMany( 20, 1 );
//		CHECK_EQUAL( 20, g.score() );
//	}
}

#endif // ALGEBRA_H_INCLUDED
